package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.IOrganizationStoreDepartDao;
import com.kayt.cyberBar.cuser.business.entity.po.BOrganizationStoreDepart;

@Repository("organizationStoreDepartDao")
public class OrganizationStoreDepartDaoImpl implements IOrganizationStoreDepartDao {
	@Autowired
	private EntityDao entityDao;
	
	@Override
	public BOrganizationStoreDepart findById(String organizationStoreDepartId) {
		if (StringUtils.isNotEmpty(organizationStoreDepartId)) {
			Long id = null;
			id = Long.parseLong(organizationStoreDepartId);
			return entityDao.findById(id, BOrganizationStoreDepart.class);
		} else {
			return null;
		}
	}

	@Override
	public Integer delete(String organizationStoreDepartId) {
		if (StringUtils.isNotEmpty(organizationStoreDepartId)) {
			Long id = null;
			id = Long.parseLong(organizationStoreDepartId);
			BOrganizationStoreDepart BOrganizationStoreDepart = entityDao.findById(id, BOrganizationStoreDepart.class);
			if (BOrganizationStoreDepart != null) {
				entityDao.delete(BOrganizationStoreDepart);
				return 0;
			} else {
				return -1;
			}
		} else {
			return -1;
		}
	}

	@Override
	public void modify(BOrganizationStoreDepart entity) throws SQLException {
		entityDao.update(entity);
	}

	@Override
	public PageData<BOrganizationStoreDepart> findByPage(Integer pageNum,Integer pageSize,String hql, Object[] params, LinkedHashMap<String, String> orderMap)
			throws SQLException {
		PageData<BOrganizationStoreDepart> organizationStoreDepartPageData = this.entityDao.getPagingData(BOrganizationStoreDepart.class, pageNum, pageSize, hql, params,
				orderMap);
		return organizationStoreDepartPageData;
	}

	@Override
	public BOrganizationStoreDepart save(BOrganizationStoreDepart entity) throws SQLException {
		Long id = entityDao.save(entity);
		entity.setId(id);
		return entity;
	}
	@Override
	public PageData<BOrganizationStoreDepart> getOrganizationStoreDepartList(LinkedHashMap<String, String> orderMap) throws SQLException {
		PageData<BOrganizationStoreDepart> organizationStoreDepartPageData = this.entityDao.getPagingData(BOrganizationStoreDepart.class, -1, -1, null, null, orderMap);
		return organizationStoreDepartPageData;
	}

	@Override
	public BOrganizationStoreDepart findByStoreCodeAndDepartCode(String storeCode, String departCode) throws SQLException {
		String whereSql = "o.departCode= '"+departCode+"' and o.storeCode = '"+storeCode+"'";
		return entityDao.getObj(BOrganizationStoreDepart.class, whereSql, null);
	}
}
